package com.session03.homework;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class StudentMap {
    //利用1题的学生类，
    // 增加两个个属性学号和密码，然后完成一个登陆效果。多个学生对象放到Map集合当中。
    public static void main(String[] args) {
        Map<String, Student> map = new HashMap<>();
        Student stu1 = new Student("张三", 18, 80, "003", "1234563");
        Student stu2 = new Student("李四", 19, 90, "004", "1234564");
        Student stu3 = new Student("王五", 20, 75, "005", "1234565");

        map.put("张三", stu1);
        map.put("李四", stu2);
        map.put("王五", stu3);

        /*System.out.println("欢迎来到学生登陆界面");
        System.out.println("请输入用户名：");
        Scanner input = new Scanner(System.in);
        String s = input.next();

        Set<String> keySet = map.keySet();
        for (String str : keySet) {
            if (str.equals(s)) {
                System.out.println("登陆成功");
                break;
            }
        }*/

        for (int i = 0; i < 3; i++) {
            Scanner input = new Scanner(System.in);
            System.out.println("请输入用户名：");
            String name = input.next();
            System.out.println("请输入密码：");
            String pwd = input.next();

            if (map.containsKey(name)) {
                Student stu = map.get(name);
                //System.out.println(map.get(name));
                if (stu.getPassword().equals(pwd)) {
                    System.out.println("登陆成功");
                    break;
                }
            }
            System.out.println("用户名/密码有误");
        }
    }
}
